/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package fr.ove.openmath.jome.ctrl.om;

/**
 *
 * @author Mr.Sam
 */
import fr.ove.utils.CachingResourcesManager;

/**
*
*
* @author © 1999 DIRAT Laurent
* @version 2.0  30/09/99
*/
public class OMParserResourcesManager extends CachingResourcesManager {
    /**
    * The Constructor.
    * @param resourcesName the name of the resources file.
    */
    public OMParserResourcesManager (String resourcesName) {
        super(resourcesName);
    }
    
    /**
    * Returns the class name corresponding to the specified property.
    * @param property the specified property
    */
    public String getIdentifier(String property) {
        return accessResource(property, 0);
    }
    
    /**
    * Returns the value associated to corresponding to the specified property.
    * @param property the specified property
    */
    public String getValue(String property) {
        return accessResource(property, 1);
    }
    
    /**
    * Returns the arity of the symbol associated to the specified property.
    * @param property the specified property
    */
    public byte getArity(String property) {
        String arity = accessResource(property, 2);
        byte byteArity = -1;
        try {
            byteArity = Byte.parseByte(arity);
        }
        catch (NumberFormatException nfe) {
            nfe.printStackTrace();
        }
        
        return byteArity;
    }
        
    /**
    * Returns the list of supported cds.
    */
    public String[] getSupportedCDs() {
        return getResourceStrings("supportedCDs");
    }
    
    /**
    * Checks if the specified cd name is a supported cd.
    * @param cdName the name of the cd
    * @return <CODE>true</CODE> if the cd is supported. <CODE>false</CODE> otherwise.
    */
    public boolean isSupportedCD(String cdName) {
        String[] supportedCDs = getResourceStrings("supportedCDs");
        
        if (supportedCDs.length > 0) {
            for (int i = 0; i < supportedCDs.length; i++) {
                if (supportedCDs[i].equals(cdName))
                    return true;
            }
        }
        
        return false;
    }
    
    /**
    * Returns the supported symbols in the specified cd.
    * @param cdName the name of the cd.
    */
    public String[] getSupportedSymbols(String cdName) {
        if (isSupportedCD(cdName))
            return getResourceStrings(cdName);
            
        return new String[0];
    }
    
    /**
    * Cheks the symbol id supported.
    * @returns <CODE>true</CODE> if the symbol is supported. <CODE>false</CODE> otherwise.
    */
    public boolean isSupportedSymbol(String cdName, String symbName) {
        if (isSupportedCD(cdName)) {
            String[] supportedSymbols = getResourceStrings(cdName);
            
            if (supportedSymbols.length > 0) {
                for (int i = 0; i < supportedSymbols.length; i++) {
                    if (supportedSymbols[i].equals(symbName))
                        return true;
                }
            }
        }
        
        return false;
    }
    
    /**
    * Cheks the validity of a symbol. Here, validity means :
    * <UL>
    * <LI>the specified cd name is supported</LI>
    * <LI>the specified symbol name is supported (of course, the cd must be supported)</LI>
    * </UL>
    * @param cdName the name of the cd in which the symbol should be
    * @param symbName the name of the symbol
    * @returns <CODE>true</CODE> if the symbol is valid. <CODE>false</CODE> otherwise.
    */
    public boolean isValidSymbol(String cdName, String symbName) {
        return isSupportedCD(cdName) & isSupportedSymbol(cdName, symbName);
    }
}
